from django.db import models
import random


def default_sign():
    signs = ["来吧,兄弟", "奔跑吧,兄弟"]
    return random.choice(signs)  # 随机返回一个


# Create your models here.
class UserProfile(models.Model):
    username = models.CharField(max_length=11, verbose_name="用户名", primary_key=True)
    nickname = models.CharField(max_length=30, verbose_name="昵称")
    password = models.CharField(max_length=32)
    email = models.EmailField()
    sex_choices = (
        (1, "男"),
        (2, "女"),
    )
    sex = models.SmallIntegerField(verbose_name="性别", choices=sex_choices)
    age = models.IntegerField(verbose_name="年龄")
    phone = models.CharField(max_length=11)
    avatar = models.ImageField(upload_to="avatar", null=True)
    sign = models.CharField(max_length=50, verbose_name="个人签名", default=default_sign)
    info = models.CharField(max_length=150, verbose_name="个人简介", default='')
    create_time = models.DateTimeField(auto_now_add=True)
    update_time = models.DateTimeField(auto_now=True)

    class Meta:
        db_table = 'user_user_profile'


class AdminProfile(models.Model):
    username = models.CharField(max_length=11, verbose_name="用户名", primary_key=True)
    nickname = models.CharField(max_length=30, verbose_name="昵称")
    password = models.CharField(max_length=32)
    email = models.EmailField(null=True)
    phone = models.CharField(max_length=11)
    avatar = models.ImageField(upload_to="avatar", null=True)
    sign = models.CharField(max_length=50, verbose_name="个人签名", default=default_sign)
    info = models.CharField(max_length=150, verbose_name="个人简介", default='')
    create_time = models.DateTimeField(auto_now_add=True)
    update_time = models.DateTimeField(auto_now=True)

    class Meta:
        db_table = 'admin_user_profile'


class UserAddress(models.Model):
    username = models.CharField(max_length=11, verbose_name="用户名")
    name = models.CharField(max_length=30, verbose_name="姓名")
    phone = models.CharField(max_length=11, verbose_name="手机号")
    city = models.CharField(max_length=299, verbose_name="所属地区")
    detail = models.CharField(max_length=299, verbose_name="详细地址")
    state_choices = (
        (1, "默认"),
        (2, "非默认"),
    )
    state = models.SmallIntegerField(verbose_name="是否为默认地址", choices=state_choices)

    class Meta:
        db_table = 'user_address'


class ComClass(models.Model):
    c_id = models.IntegerField(verbose_name="类id", primary_key=True)
    c_name = models.CharField(max_length=20, verbose_name="类别名称")
    c_info = models.CharField(max_length=150, verbose_name="类别描述", default='')
    c_parent_id = models.IntegerField(verbose_name="父级分类id")
    level = models.IntegerField(verbose_name="分类所处等级")

    class Meta:
        db_table = 'com_class'


class Goods(models.Model):
    g_id = models.IntegerField(verbose_name="id", primary_key=True)
    c_id = models.IntegerField(verbose_name="类id")
    g_name = models.CharField(max_length=50, verbose_name="商品名称")
    g_time = models.DateField(auto_now=True)
    g_img = models.TextField(verbose_name="图片", max_length=65535)
    g_price = models.DecimalField(max_digits=12, decimal_places=2)
    g_info = models.CharField(max_length=200, verbose_name="商品描述")
    g_count = models.IntegerField(verbose_name="商品数量", default=1)
    g_sales = models.IntegerField(verbose_name="销量", default=1)

    class Meta:
        db_table = 'goods'


class Banner(models.Model):
    banner_id = models.IntegerField(verbose_name="id", primary_key=True)
    banner_img = models.ImageField(verbose_name="图片")
    banner_name = models.IntegerField(verbose_name="优先级")

    class Meta:
        db_table = 'banner'


class Sell_num_statistics(models.Model):
    sn_id = models.IntegerField(verbose_name="id", primary_key=True)
    c_id = models.CharField(max_length=15, verbose_name="品牌名")
    jh_number = models.IntegerField(verbose_name="进货数量")
    xs_number = models.IntegerField(verbose_name="销售数量")

    class Meta:
        db_table = 'sell_num_statistics'


class Dos_statistics(models.Model):
    dos_id = models.IntegerField(verbose_name="id", primary_key=True)
    g_id = models.IntegerField(verbose_name="品牌名")
    hp_grade = models.IntegerField(verbose_name="好评")
    zp_grade = models.IntegerField(verbose_name="中评")
    cp_grade = models.IntegerField(verbose_name="差评")

    class Meta:
        db_table = 'dos_statistics'


class Performance_statistics(models.Model):
    per_id = models.IntegerField(verbose_name="id", primary_key=True)
    c_name = models.CharField(max_length=50, verbose_name="类名")
    percentage = models.IntegerField(verbose_name="占比")
    kpi = models.IntegerField(verbose_name="总销售数量")

    class Meta:
        db_table = 'Performance_statistics'


class Old_Sell_statistics(models.Model):
    os_id = models.IntegerField(verbose_name="id", primary_key=True)
    sj_number = models.IntegerField(verbose_name="手机")
    dn_number = models.IntegerField(verbose_name="电脑")
    qt_number = models.IntegerField(verbose_name="其他")
    year_number = models.IntegerField(verbose_name="年份")
    year_kpi = models.IntegerField(verbose_name="年销售数量")

    class Meta:
        db_table = 'old_sell_statistics'


class Age_statistics(models.Model):
    Age_id = models.IntegerField(verbose_name="id", primary_key=True)
    people_number = models.IntegerField(verbose_name="总人数")
    man_number = models.IntegerField(verbose_name="男人数")
    woman_number = models.IntegerField(verbose_name="女人数")
    year_number = models.IntegerField(verbose_name="日期")

    class Meta:
        db_table = 'age_statistics'


class Return_statistics(models.Model):
    ret_id = models.IntegerField(verbose_name="id", primary_key=True)
    th_number = models.IntegerField(verbose_name="退货占比")
    ret_number = models.IntegerField(verbose_name="退货数")
    year_number = models.IntegerField(verbose_name="日期")

    class Meta:
        db_table = 'return_statistics'


class Market_research_statistics(models.Model):
    mr_id = models.IntegerField(verbose_name="id", primary_key=True)
    sc_number = models.IntegerField(verbose_name="市场总计")
    yes_number = models.IntegerField(verbose_name="满意")
    no_number = models.IntegerField(verbose_name="不满意")
    vyes_number = models.IntegerField(verbose_name="非常满意")
    vno_number = models.IntegerField(verbose_name="非常不满意")

    class Meta:
        db_table = 'market_research_statistics'

class Shopping_cart(models.Model):
    shopping_cart_id = models.IntegerField(verbose_name="id", primary_key=True)
    good_id = models.IntegerField(verbose_name="商品ID")
    user_name = models.CharField(verbose_name="用户名", max_length=20, default='')
    shopping_cart_num = models.IntegerField(verbose_name="数量")

    class Meta:
        db_table = 'shopping_cart'

class Product_Order(models.Model):
    product_order_id = models.IntegerField(verbose_name="id", primary_key=True)
    good_id = models.IntegerField(verbose_name="商品ID")
    user_name = models.CharField(verbose_name="用户名", max_length=20, default='')
    product_order_money = models.DecimalField(max_digits=12, decimal_places=2)
    product_order_num = models.IntegerField(verbose_name="数量")
    state_choices = (
        (0, "已退款"),
        (1, "待发货"),
        (2, "待收货"),
        (3, "待评价"),
        (4, "待退款"),
    )
    product_order_state = models.SmallIntegerField(verbose_name="发货状态", choices=state_choices)
    class Meta:
        db_table = 'product_order'
